<?php	
namespace Admin\Controller;
class UserController extends CommonController
{
	public function changePwd()
	{
		$password = $_SESSION['password'];
		View::with("password",$password);
		if(IS_POST){
			$password = $_POST['password'];
			$newPassword = $_POST['newPassword'];
			$confirmPassword = $_POST['confirmPassword'];
			//实例化数据库
			$UserModel = new \Common\Model\User;
			//获取输入旧密码的一条数据
			$data = $UserModel -> where("uid",$_SESSION["uid"]) ->first();
			if($data['password'] != md5($password))
			{
				$this -> error("旧密码错误");
			}
			if($newPassword != $confirmPassword)
			{
				$this -> error ("两次密码不一致");
			}
			//执行修改
			$newPassword = md5($newPassword);
			$UserModel -> where("uid",$_SESSION['uid']) -> update(array('password'=>$newPassword));
			//重新登录
			session_unset();
			session_destroy();
//			$this -> success("密码修改成功" , U("Index/index"));
			go("Index/index");
		}
		View::make();
	}
}
